//引入JS文件->  wangEditor.min.js
document.write("<script language='javascript' src='./wangEditor.min.js'></script>");//项目绝对路径

const url = "/upload.html"; //上传接口

//整合上传方法，初始化基本配置
function utilEditor(id, uploadServer = url) {
    const E = window.wangEditor;
    const editor = new E(document.getElementById(id));
    editor.config.uploadImgServer = editor.config.uploadVideoServer = uploadServer;
    editor.config.uploadFileName = editor.config.uploadVideoName = 'file';
    editor.config.showLinkImg = editor.config.showLinkVideo = false;
    editor.config.uploadVideoHooks = editor.config.uploadImgHooks = {
        // 上传图片之前
        before: function (xhr) {
        },
        // 图片上传并返回了结果，图片插入已成功
        success: function (xhr) {
        },
        // 图片上传并返回了结果，但图片插入时出错了
        fail: function (xhr, editor, resData) {
        },
        // 上传图片出错，一般为 http 请求的错误
        error: function (xhr, editor, resData) {
        },
        // 上传图片超时
        timeout: function (xhr) {
        },
        // 图片上传并返回了结果，想要自己把图片插入到编辑器中
        customInsert: function (insertImgFn, result) {
            insertImgFn(result.data['signLink'])
        }
    }
    editor.create();

    return editor;
}
